import { get, post } from '../../http'
import store from '@/store'

// 获取保证金数据
export const queryBondList = data =>
  post('/FTKJWLHYPT/base/sysBondList', {
    Data: {
      Parameters: {
        FTKJWLHYPT: {
          fltName: data.fltName,
          fltId: store.state.user.ROLE_TYPE_DX_H == 'g' ? store.state.user.FLT_UUID_DX_H : data.fltId,
          bidId: data.bidId,
          bondMode: data.rvCmeaning,
          bondStatus: data.bondStatus,
          bidCode: data.bidCode
          // dptId: store.state.user.DPTID_DX_H,
        }
      },
      PageIndex: {
        FTKJWLHYPT: data.PageIndex
      },
      PageSize: {
        FTKJWLHYPT: data.PageSize
      }
    }
  })
//新增
export const addSysBond = data =>
  post('/FTKJWLHYPT/base/addSysBond', {
    Data: {
      Parameters: {
        FTKJWLHYPT: {
          bond: data.bond,
          bondStatus: data.bondStatus,
          fltId: store.state.user.ROLE_TYPE_DX_H == 'g' ? store.state.user.FLT_UUID_DX_H : data.fltId,
          creator: store.state.user.USR_CODE_DX_H,
          dptId: store.state.user.DPTID_DX_H,
          lastmodifier: store.state.user.USR_CODE_DX_H,
          remarks: data.remarks,
          bidId: data.bidId,
          bondMode: data.bondMode,
          no: data.no // 保证金交易流水号
          // fltUuid: store.state.user.fltUuid_DX_H,
          //   ctyeShrcode:data.ctyeShrcode,
          //   ctyeRemark:data.ctyeRemark,
          //   ctyeShrchn:data.ctyeShrchn,
          //   ctyeCityId:data.ctyeCityId ,
          //   ctyeIsvalid:data.ctyeIsvalid,
          //   ctyePrename:data.ctyePrename,
          //   ctyeInsertuser:store.state.user.USR_CODE_DX_H
        }
      }
    }
  })
//编辑
export const editSysBond = data =>
  post('/FTKJWLHYPT/base/editSysBond', {
    Data: {
      Parameters: {
        FTKJWLHYPT: {
          bond: data.bond,
          bondStatus: data.bondStatus,
          fltId: data.fltId,
          bondId: data.bondId,
          lastmodifier: store.state.user.USR_CODE_DX_H,
          remarks: data.remarks,
          bidId: data.bidId,
          bondMode: data.bondMode
        }
      }
    }
  })
//删除
export const delSysBond = data =>
  post('/FTKJWLHYPT/base/delSysBond', {
    Data: {
      Parameters: {
        FTKJWLHYPT: {
          bondId: data.bondId,
          lastmodifier: store.state.user.USR_CODE_DX_H
        }
      }
    }
  })
//删除
export const selectByBidId = data =>
  post('/FTKJWLHYPT/base/selectByBidId', {
    Data: {
      Parameters: {
        FTKJWLHYPT: {
          bidId: data.bidId
        }
      }
    }
  })
//退回
export const returnSysbond = data =>
  post('/FTKJWLHYPT/base/updateSysBondStatus', {
    Data: {
      Parameters: {
        FTKJWLHYPT: {
          bondId: data.bondId,
          lastmodifier: store.state.user.USR_CODE_DX_H
        }
      }
    }
  })

/**
 * 查询支付平台支付/退款结果
 * @param no
 * @param type
 * @returns {Promise | Promise<unknown>}
 */
export const queryPayResult = ({ no, type }) =>
  post('/FTKJWLHYPT/bond/queryPayResult', {
    Data: {
      Parameters: {
        FTKJWLHYPT: {
          query_type: type, // 查询类型 0 支付 1 退款
          biz_no: no // 订单号
        }
      }
    }
  })

/**
 * 判断用户是否注册过，如果未注册，直接注册用户
 * @param id
 * @returns {Promise | Promise<unknown>}
 */
export const isSyncUserAndSync = id => get(`/FTKJWLHYPT/bond/isSync/${id}`)

/**
 * 查询未退回保证金的标
 * @param data
 * @returns {Promise | Promise<unknown>}
 */
export const noRefuseDocuments = data =>
  post('/FTKJWLHYPT/bond/noRefuseDocuments', {
    Data: {
      Parameters: {
        FTKJWLHYPT: {
          name: data.name
        }
      },
      PageIndex: {
        FTKJWLHYPT: data.PageIndex
      },
      PageSize: {
        FTKJWLHYPT: data.PageSize
      }
    }
  })

/**
 * 退回竞价保证金
 * @param ids
 * @returns {Promise | Promise<unknown>}
 */
export const doRefuseDocuments = ({ ids }) =>
  post('/FTKJWLHYPT/bond/doRefuseDocuments', {
    Data: {
      Parameters: {
        FTKJWLHYPT: {
          ids
        }
      }
    }
  })
